$(document).ready(function() {
	$(".o-l-table tbody tr td[class!='o-l-tab-ckb']").click(function (){
		var $this = $(this).parent();
		window.open($this.attr('data-herf'), $this.attr('data-target'));  
	});
	$("input[type='checkbox'][data-ckb='all']").click(function (){
		var $this = $(this);
		var $tab = $this.closest("table");
		if($this.prop('checked')){
			$tab.find("input[type='checkbox'][data-ckb-id]").each(function(){
				if($(this).attr("disabled") !="disabled" ){
					$(this).prop("checked",true);
				}
			});
		}else{
			$tab.find("input[type='checkbox'][data-ckb-id]").each(function(){
				$(this).prop("checked",false);
			});
		}
	});
	$("input[type='checkbox'][data-ckb-id]").click(function (){
		var $this = $(this);
		var $tab = $this.closest("table");
		if($this.prop('checked')){
			$tab.find("input[type='checkbox'][data-ckb='all']").each(function (){
				//this.checked = true;
				$(this).prop("checked",true);
			});
		}else{
			var len = $tab.find("input[type='checkbox'][data-ckb-id]:checked").length;
			if(len==0){
				$tab.find("input[type='checkbox'][data-ckb='all']").prop("checked",false);
			}
		}
	});
});
function funform(url,target){
	//alert(url+"   "+target);
	window.open(url,target);
}

/**
 * modify by xiaohan 删除选中的项
 * @param href	URL
 * @param tabId  搜索范围
 * @param urlParam   要替换为具体ID的字符
 */
function Oosp_DelChked(href,tabId,urlParam){
	var ids = new Array();
	var nos = new Array();
	var names = new Array();
	$('#'+tabId).find("input[type='checkbox'][data-ckb-id]").each(function(){
		var $this = $(this);
		if($this.prop('checked')){
			ids.push($(this).attr("data-ckb-id"));
			nos.push($(this).attr("data-ckb-no"));
			names.push($(this).attr("data-ckb-name"));
		}
	});
	if(ids.length==0){
		$.jBox.tip("请先勾选需要删除的数据！","${error}",{persistent:true,opacity:0});
	}else{
		top.$.jBox.confirm('确认要删除该条数据吗？','系统提示',function(v,h,f){
			if(v=='ok'){	
				Oosp_Loading('正在提交，请稍等...');
				
				if(urlParam){
					href = href.replace(urlParam,ids+'');
				}
				if(nos !=''){
					
					funform(href+"&nos="+nos+''+"&names="+names+'','_self');
				}else{
					funform(href,'_self');
				}
			}
		},{buttonsFocus:1});
	}
}
function Oosp_TurnOverPage(pageNo){
	document.listForm.pageNo.value=pageNo;
	document.listForm.submit();
}
function Oosp_GoTo(){
	var val = document.listForm.gotoPageNo.value;
	if(val!="" && val*1>0){
		document.listForm.pageNo.value=val;
		document.listForm.submit();
	}else{
		return false;
	}
}
function Oosp_DelAll(action,tableId){
	var deleteIds = "";
	$('#'+tableId).find("input[type='checkbox'][data-ckb-id]:checked").each(function(){
		deleteIds += ";"+$(this).attr("data-ckb-id");
	});
	if(deleteIds == ""){
		alert("请选择要删除的数据！");
	}else{
		if(confirm("确认要删除已选中的数据吗？")){
			document.listForm.deleteIds.value = deleteIds.substring(1);
			document.listForm.action = action;
			document.listForm.submit();
		}
	}
}

